package com.itheima.ydd.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.ydd.dto.CateInfo;
import com.itheima.ydd.entity.Cate;
import com.itheima.ydd.entity.Role;
import com.itheima.ydd.entity.User;
import com.itheima.ydd.mapper.CateMapper;
import com.itheima.ydd.service.CateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

@Service
public class CateServiceImpl extends ServiceImpl<CateMapper, Cate> implements CateService {
    @Autowired
    private CateMapper cateMapper;

    @Override
    public List<CateInfo> getAllCate() {
        return null;
    }

    @Override
    public HashMap<String, Object> getPageHashMap(String catename, Integer page, Integer limit) {
        Page<Cate> catePage = new Page<>(page, limit);
        LambdaQueryWrapper<Cate> lqw = new LambdaQueryWrapper<>();
        lqw.like(catename != null, Cate::getCatename, catename);
        this.page(catePage, lqw);
        List<Cate> records = catePage.getRecords();
        Integer count = this.count(lqw);
        HashMap<String, Object> map = new HashMap<>();
        map.put("count", count);
        map.put("currentPage", page);
        map.put("pageSize", limit);
        map.put("totalPages", catePage.getTotal());
        map.put("data", records);
        return map;
    }


}
